#include <jni.h>
#include <string>

extern "C" {
extern int merge(int argc, char *argv[]);
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_jinsp_incrementalupdate_IncrementalUpdateUtil_mergePatch(JNIEnv *env, jclass clazz,
                                                                  jstring src_apk_file_path,
                                                                  jstring new_apk_file_path,
                                                                  jstring patch_file_path) {

    int argc = 4;
    char *argv[argc];
    argv[0] = "bspatch";
    argv[1] = const_cast<char *>(env->GetStringUTFChars(src_apk_file_path, 0));
    argv[2] = const_cast<char *>(env->GetStringUTFChars(new_apk_file_path, 0));
    argv[3] = const_cast<char *>(env->GetStringUTFChars(patch_file_path, 0));
    int result = merge(argc, argv);
    env->ReleaseStringUTFChars(src_apk_file_path, argv[1]);
    env->ReleaseStringUTFChars(new_apk_file_path, argv[2]);
    env->ReleaseStringUTFChars(patch_file_path, argv[3]);
    return result;
}